package Janela;

import Modelo.Suspeitos;
import Dao.SuspeitosDAO;
import UTIL.ManipularImagem;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Victor
 */
public class SuspeitosGUI extends javax.swing.JInternalFrame {

    List<Suspeitos> lista = new ArrayList<Suspeitos>();
    SuspeitosDAO dao;
    Integer posicaoLista;
    BufferedImage imagem;

    public SuspeitosGUI() {
        initComponents();
        dao = new SuspeitosDAO();
        lista = dao.Listar();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        btnPrimeiro = new javax.swing.JButton();
        btnUltimo = new javax.swing.JButton();
        btnAnterior = new javax.swing.JButton();
        btnProximo = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        lblImagem = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel21 = new javax.swing.JLabel();
        txtCodigo2 = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        btnSelecionar2 = new javax.swing.JButton();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        txtNomesuspeito2 = new javax.swing.JTextField();
        txtCabelo2 = new javax.swing.JTextField();
        txtCarro2 = new javax.swing.JTextField();
        txtTracos2 = new javax.swing.JTextField();
        txtOutros2 = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        cbxSexo2 = new javax.swing.JComboBox();
        jLabel29 = new javax.swing.JLabel();
        txtEsporte2 = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        txtOcupacao2 = new javax.swing.JTextField();
        lblExibicao = new javax.swing.JLabel();
        btnTodos = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        btnInserir = new javax.swing.JButton();
        btnConsultar = new javax.swing.JButton();
        btnRemover = new javax.swing.JButton();
        btnNovo = new javax.swing.JButton();
        btnAtualizar = new javax.swing.JButton();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Navegação"));

        btnPrimeiro.setText("Primeiro");
        btnPrimeiro.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrimeiroActionPerformed(evt);
            }
        });

        btnUltimo.setText("Último");
        btnUltimo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUltimoActionPerformed(evt);
            }
        });

        btnAnterior.setText("Anterior");
        btnAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnteriorActionPerformed(evt);
            }
        });

        btnProximo.setText("Próximo");
        btnProximo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProximoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnPrimeiro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnAnterior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnProximo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnUltimo, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnPrimeiro)
                    .addComponent(btnUltimo)
                    .addComponent(btnAnterior)
                    .addComponent(btnProximo))
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Imagem"));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblImagem, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(lblImagem, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel21.setText("Nome:");

        txtCodigo2.setEditable(false);

        jLabel22.setText("Código");

        jLabel23.setText("Imagem:");

        btnSelecionar2.setText("Selecionar Imagem");
        btnSelecionar2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSelecionar2ActionPerformed(evt);
            }
        });

        jLabel24.setText("Cabelo:");

        jLabel25.setText("Carro:");

        jLabel26.setText("Traços:");

        jLabel27.setText("Outros:");

        jLabel28.setText("Sexo:");

        cbxSexo2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Masculino", "Feminino" }));

        jLabel29.setText("Esporte:");

        jLabel30.setText("Ocupação:");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(68, 68, 68)
                .addComponent(cbxSexo2, 0, 141, Short.MAX_VALUE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel23)
                        .addGap(18, 18, 18)
                        .addComponent(btnSelecionar2))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(txtCodigo2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(txtNomesuspeito2, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(txtCabelo2, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(txtCarro2, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(txtEsporte2, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel24)
                                    .addComponent(jLabel21)
                                    .addComponent(jLabel22)
                                    .addComponent(jLabel25)
                                    .addComponent(jLabel28)
                                    .addComponent(jLabel29)
                                    .addComponent(jLabel30)))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel26))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jLabel27)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtOcupacao2)
                            .addComponent(txtTracos2, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtOutros2, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCodigo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel22))
                .addGap(8, 8, 8)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNomesuspeito2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel21))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel24)
                    .addComponent(txtCabelo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(txtCarro2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel28)
                    .addComponent(cbxSexo2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel29)
                    .addComponent(txtEsporte2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel30)
                    .addComponent(txtOcupacao2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTracos2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel26))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel27)
                    .addComponent(txtOutros2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(20, 20, 20)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSelecionar2)
                    .addComponent(jLabel23))
                .addContainerGap())
        );

        lblExibicao.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblExibicao.setForeground(new java.awt.Color(204, 0, 0));
        lblExibicao.setText("Todos os registros");

        btnTodos.setText("Todos");
        btnTodos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTodosActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Ações"));

        btnInserir.setText("Inserir");
        btnInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnInserirActionPerformed(evt);
            }
        });

        btnConsultar.setText("Consultar");
        btnConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConsultarActionPerformed(evt);
            }
        });

        btnRemover.setText("Remover");
        btnRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoverActionPerformed(evt);
            }
        });

        btnNovo.setText("Novo");
        btnNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNovoActionPerformed(evt);
            }
        });

        btnAtualizar.setText("Atualizar");
        btnAtualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAtualizarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnInserir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnConsultar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnAtualizar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnRemover)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnNovo)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnInserir)
                    .addComponent(btnConsultar)
                    .addComponent(btnRemover)
                    .addComponent(btnNovo)
                    .addComponent(btnAtualizar))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblExibicao)
                                .addGap(245, 245, 245)
                                .addComponent(btnTodos))
                            .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblExibicao)
                    .addComponent(btnTodos))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(17, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnPrimeiroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrimeiroActionPerformed

        Suspeitos jogo = lista.get(0);

        txtCodigo2.setText(jogo.getSuspeitoid().toString());
        txtNomesuspeito2.setText(jogo.getNomesuspeito());
        cbxSexo2.setSelectedItem(jogo.getSexo());
        txtOcupacao2.setText(jogo.getOcupacao());
        txtEsporte2.setText(jogo.getEsporte());
        txtCabelo2.setText(jogo.getCabelo());
        txtCarro2.setText(jogo.getCarro());
        txtTracos2.setText(jogo.getTracos());
        txtOutros2.setText(jogo.getOutros());
        exibeImagem(jogo.getImagem());

        posicaoLista = 0;
    }//GEN-LAST:event_btnPrimeiroActionPerformed

    private void btnUltimoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUltimoActionPerformed
        Suspeitos jogo = lista.get(lista.size() - 1);

        txtCodigo2.setText(jogo.getSuspeitoid().toString());
        txtNomesuspeito2.setText(jogo.getNomesuspeito());
        cbxSexo2.setSelectedItem(jogo.getSexo());
        txtOcupacao2.setText(jogo.getOcupacao());
        txtEsporte2.setText(jogo.getEsporte());
        txtCabelo2.setText(jogo.getCabelo());
        txtCarro2.setText(jogo.getCarro());
        txtTracos2.setText(jogo.getTracos());
        txtOutros2.setText(jogo.getOutros());
        exibeImagem(jogo.getImagem());

        posicaoLista = lista.size() - 1;
    }//GEN-LAST:event_btnUltimoActionPerformed

    private void btnAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnteriorActionPerformed
        if (posicaoLista > 0) {
            posicaoLista = posicaoLista - 1;
            Suspeitos jogo = lista.get(posicaoLista);

            txtCodigo2.setText(jogo.getSuspeitoid().toString());
            txtNomesuspeito2.setText(jogo.getNomesuspeito());
            cbxSexo2.setSelectedItem(jogo.getSexo());
            txtOcupacao2.setText(jogo.getOcupacao());
            txtEsporte2.setText(jogo.getEsporte());
            txtCabelo2.setText(jogo.getCabelo());
            txtCarro2.setText(jogo.getCarro());
            txtTracos2.setText(jogo.getTracos());
            txtOutros2.setText(jogo.getOutros());
            exibeImagem(jogo.getImagem());

        }
    }//GEN-LAST:event_btnAnteriorActionPerformed

    private void btnProximoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProximoActionPerformed
        if (posicaoLista < (lista.size() - 1)) {
            posicaoLista = posicaoLista + 1;
            Suspeitos jogo = lista.get(posicaoLista);

            txtCodigo2.setText(jogo.getSuspeitoid().toString());
            txtNomesuspeito2.setText(jogo.getNomesuspeito());
            cbxSexo2.setSelectedItem(jogo.getSexo());
            txtOcupacao2.setText(jogo.getOcupacao());
            txtEsporte2.setText(jogo.getEsporte());
            txtCabelo2.setText(jogo.getCabelo());
            txtCarro2.setText(jogo.getCarro());
            txtTracos2.setText(jogo.getTracos());
            txtOutros2.setText(jogo.getOutros());
            exibeImagem(jogo.getImagem());
        }
    }//GEN-LAST:event_btnProximoActionPerformed

    private void btnSelecionar2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelecionar2ActionPerformed
        JFileChooser fc = new JFileChooser();
        int res = fc.showOpenDialog(null);
        if (res == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            imagem = ManipularImagem.setImagemDimensao(file.getAbsolutePath(), 160, 160);
            lblImagem.setIcon(new ImageIcon(imagem));
        }
    }//GEN-LAST:event_btnSelecionar2ActionPerformed

    private void btnTodosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTodosActionPerformed
        lista = dao.Listar();
        lblExibicao.setText("Todos os registros");

        Modelo.Suspeitos jogo = lista.get(posicaoLista);
        posicaoLista = 0;
        txtCodigo2.setText(jogo.getSuspeitoid().toString());
        txtNomesuspeito2.setText(jogo.getNomesuspeito());
        cbxSexo2.setSelectedItem(jogo.getSexo());
        txtOcupacao2.setText(jogo.getOcupacao());
        txtEsporte2.setText(jogo.getEsporte());
        txtCabelo2.setText(jogo.getCabelo());
        txtCarro2.setText(jogo.getCarro());
        txtTracos2.setText(jogo.getTracos());
        txtOutros2.setText(jogo.getOutros());
        exibeImagem(jogo.getImagem());
    }//GEN-LAST:event_btnTodosActionPerformed

    private void btnInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInserirActionPerformed
        Suspeitos jogo = new Suspeitos();

        jogo.setNomesuspeito(txtNomesuspeito2.getText());
        jogo.setSexo(cbxSexo2.getSelectedItem().toString());
        jogo.setOcupacao(txtOcupacao2.getText());
        jogo.setEsporte(txtEsporte2.getText());
        jogo.setCabelo(txtCabelo2.getText());
        jogo.setCarro(txtCarro2.getText());
        jogo.setTracos(txtTracos2.getText());
        jogo.setOutros(txtOutros2.getText());
        jogo.setImagem(ManipularImagem.getImgBytes(imagem));

        Boolean retorno = dao.Cadastrar(jogo);
        if (retorno = true) {
            JOptionPane.showMessageDialog(null, "Suspeito inserido com sucesso");
            lista = dao.Listar();
        } else {
            JOptionPane.showMessageDialog(null, "Erro ao inserir registro");
        }

        limparDados();
    }//GEN-LAST:event_btnInserirActionPerformed

    private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConsultarActionPerformed
        String consulta
                = JOptionPane.showInputDialog("Informe o nome do suspeito a ser"
                        + " consultado ");

        boolean encontrou = false;

        int i = 0;
        lista = dao.Consultar(consulta);
        encontrou = (lista.size() > 0);
        String saidaLabel = "";
        if (encontrou == false) {
            saidaLabel = "Filtrando por: " + consulta + ". Nenhum registro encontrado";
            limparDados();
        } else {
            saidaLabel = "Filtrando por: " + consulta + ". Exibindo " + lista.size() + " registros";

            Modelo.Suspeitos jogo = lista.get(posicaoLista);
            posicaoLista = 0;
            txtCodigo2.setText(jogo.getSuspeitoid().toString());
            txtNomesuspeito2.setText(jogo.getNomesuspeito());
            cbxSexo2.setSelectedItem(jogo.getSexo());
            txtOcupacao2.setText(jogo.getOcupacao());
            txtEsporte2.setText(jogo.getEsporte());
            txtCabelo2.setText(jogo.getCabelo());
            txtCarro2.setText(jogo.getCarro());
            txtTracos2.setText(jogo.getTracos());
            txtOutros2.setText(jogo.getOutros());
            exibeImagem(jogo.getImagem());
        }
        lblExibicao.setText(saidaLabel);
    }//GEN-LAST:event_btnConsultarActionPerformed

    private void btnRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoverActionPerformed
        int confirma = JOptionPane.showConfirmDialog(null, "Deseja excluir o suspeito?");

        if (confirma == 0) {

            Suspeitos obj = new Suspeitos();
            obj.setSuspeitoid(Integer.parseInt(txtCodigo.getText()));
            Boolean retorno = dao.Excluir(obj);
            if (retorno) {
                limparDados();
                JOptionPane.showMessageDialog(null, "Suspeito excluído com sucesso!");
                lista = dao.Listar();
            } else {
                JOptionPane.showMessageDialog(null, "Falha na exclusão do registro!");
                lista = dao.Listar();
            }

        }
    }//GEN-LAST:event_btnRemoverActionPerformed

    private void btnNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNovoActionPerformed
        limparDados();
    }//GEN-LAST:event_btnNovoActionPerformed

    private void btnAtualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAtualizarActionPerformed
        Suspeitos jogo = new Suspeitos();

        jogo.setNomesuspeito(txtNomesuspeito2.getText());
        jogo.setSexo(cbxSexo2.getSelectedItem().toString());
        jogo.setOcupacao(txtOcupacao2.getText());
        jogo.setEsporte(txtEsporte2.getText());
        jogo.setCabelo(txtCabelo2.getText());
        jogo.setCarro(txtCarro2.getText());
        jogo.setTracos(txtTracos2.getText());
        jogo.setOutros(txtOutros2.getText());
        jogo.setImagem(ManipularImagem.getImgBytes(imagem));
        jogo.setSuspeitoid(Integer.parseInt(txtCodigo2.getText()));

        Boolean retorno = dao.Atualizar(jogo);
        if (retorno) {
            JOptionPane.showMessageDialog(null, "Suspeito atualizado com sucesso!");
            limparDados();
            lista = dao.Listar();
        } else {
            JOptionPane.showMessageDialog(null, "Falha na atualização do registro!");
        }
    }//GEN-LAST:event_btnAtualizarActionPerformed

    private void exibeImagem(byte[] minhaimagem) {
        //primeiro verifica se tem a imagem
        //se tem convert para inputstream que é o formato reconhecido pelo ImageIO

        if (minhaimagem != null) {
            InputStream input = new ByteArrayInputStream(minhaimagem);
            try {
                imagem = ImageIO.read(input);
            } catch (IOException ex) {
            }
            lblImagem.setIcon(new ImageIcon(imagem));

        } else {
            lblImagem.setIcon(null);
            imagem = null;
        }

    }

    public void limparDados() {
        txtCodigo2.setText("");
        txtNomesuspeito2.setText("");
        cbxSexo2.setSelectedIndex(-1);
        txtOcupacao2.setText("");
        txtEsporte2.setText("");
        txtCabelo2.setText("");
        txtCarro2.setText("");
        txtTracos2.setText("");
        txtOutros2.setText("");
        lblImagem.setIcon(null);

    }

    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SuspeitosGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SuspeitosGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SuspeitosGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SuspeitosGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SuspeitosGUI().setVisible(true);
            }
        });
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAnterior;
    private javax.swing.JButton btnAtualizar;
    private javax.swing.JButton btnConsultar;
    private javax.swing.JButton btnInserir;
    private javax.swing.JButton btnNovo;
    private javax.swing.JButton btnPrimeiro;
    private javax.swing.JButton btnProximo;
    private javax.swing.JButton btnRemover;
    private javax.swing.JButton btnSelecionar;
    private javax.swing.JButton btnSelecionar1;
    private javax.swing.JButton btnSelecionar2;
    private javax.swing.JButton btnTodos;
    private javax.swing.JButton btnUltimo;
    private javax.swing.JComboBox cbxSexo;
    private javax.swing.JComboBox cbxSexo1;
    private javax.swing.JComboBox cbxSexo2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JLabel lblExibicao;
    private javax.swing.JLabel lblImagem;
    private javax.swing.JTextField txtCabelo;
    private javax.swing.JTextField txtCabelo1;
    private javax.swing.JTextField txtCabelo2;
    private javax.swing.JTextField txtCarro;
    private javax.swing.JTextField txtCarro1;
    private javax.swing.JTextField txtCarro2;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtCodigo1;
    private javax.swing.JTextField txtCodigo2;
    private javax.swing.JTextField txtEsporte;
    private javax.swing.JTextField txtEsporte1;
    private javax.swing.JTextField txtEsporte2;
    private javax.swing.JTextField txtNomesuspeito;
    private javax.swing.JTextField txtNomesuspeito1;
    private javax.swing.JTextField txtNomesuspeito2;
    private javax.swing.JTextField txtOcupacao;
    private javax.swing.JTextField txtOcupacao1;
    private javax.swing.JTextField txtOcupacao2;
    private javax.swing.JTextField txtOutros;
    private javax.swing.JTextField txtOutros1;
    private javax.swing.JTextField txtOutros2;
    private javax.swing.JTextField txtTracos;
    private javax.swing.JTextField txtTracos1;
    private javax.swing.JTextField txtTracos2;
    // End of variables declaration//GEN-END:variables
}
